package com.qf.day13.homework;

import java.util.HashMap;
import java.util.Scanner;

import static java.lang.Character.charCount;

public class Homework1 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入一个字符串");
        String str=scanner.nextLine();
        HashMap<Character,Integer> hashMap=charCount(str);
        System.out.println(hashMap);
    }
    private static HashMap<Character, Integer> charCount(String str) {
        HashMap<Character,Integer> hashMap=new HashMap<>();
        char[] array = str.toCharArray();

        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
            if(hashMap.containsKey(array[i])){
                //获取该键的值
                int count=hashMap.get(array[i]);
                hashMap.put(array[i],count+1);
            }else{
                hashMap.put(array[i],1);
            }
        }
        return hashMap;
    }
}
